@echo off
chcp 65001
setlocal enabledelayedexpansion

set buildType=%1
set packageName=%2
if not defined packageName (
	set packageName=%buildType%
)
set projectPath=C:\mateurp_pipline\mateurp\mateurp
set curr_buildIdFile=%projectPath%\Build\build_id_%buildType%.txt
set /p curr_buildId=<%curr_buildIdFile%

set aarFileNameOrgin=mate_android_%packageName%.aar
set aarFileName=mate_android_%packageName%_%curr_buildId%.aar

for /f "tokens=2 delims=:" %%i in ('ipconfig ^| findstr /R "IPv4"') do (
    set ip=%%i
)
set ip=%ip:~1%
set downloadUrl=http://%ip%/

if "%buildType%"=="DEBUG" (
	move /Y %projectPath%\Build\Android\DEBUG\MateAi\unityLibrary\build\outputs\aar\unityLibrary-debug.aar C:\mateurp_pipline\Mate\%aarFileName%
)

if "%buildType%"=="RELEASE" (
	move /Y %projectPath%\Build\Android\RELEASE\MateAi\unityLibrary\build\outputs\aar\unityLibrary-release.aar C:\mateurp_pipline\Mate\%aarFileName%
)
echo downloadUrl: %downloadUrl%%aarFileName%
copy /Y  C:\mateurp_pipline\Mate\%aarFileName% C:\mateurp_pipline\Mate\%aarFileNameOrgin%


set buildDir=C:\mateurp_pipline\mateurp\mateurp\Build\Android\%buildType%\MateAi\unityLibrary
set symbolFileName=mate_android_symbols_%packageName%_%curr_buildId%.zip
"C:\Program Files\7-Zip\7z.exe" a -r "%buildDir%\symbols.zip" "%buildDir%\symbols\*"
move /Y "%buildDir%\symbols.zip" C:\mateurp_pipline\Mate\%symbolFileName%
set symbleUrl=http://%ip%/%symbolFileName%
echo symbleUrl: %symbleUrl%

set json="{\"text\":{\"content\":\"本地安卓AAR打包完成,下载地址 %downloadUrl%%aarFileName% or %downloadUrl%%aarFileNameOrgin%  符号地址 %symbleUrl%\" },\"msgtype\":\"text\"}"
echo %json%
curl --ssl-no-revoke -H "Content-Type: application/json" -X POST -d !json! https://oapi.dingtalk.com/robot/send?access_token=1dd9ef311951334ba9e001f194f78c99ee8b74fff2c56b5f899c1727302f60b8

endlocal